home *** CD-ROM | disk | FTP | other *** search
- unit M1Main;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, Buttons, ExtCtrls;
-
- type
- TForm1 = class(TForm)
- Panel1: TPanel;
- Label2: TLabel;
- Label3: TLabel;
- Bevel1: TBevel;
- BitBtn2: TBitBtn;
- BitBtn1: TBitBtn;
- BitBtn4: TBitBtn;
- Label1: TLabel;
- ListBox1: TListBox;
- Label5: TLabel;
- OpenDialog1: TOpenDialog;
- Label4: TLabel;
- procedure BitBtn2Click(Sender: TObject);
- procedure BitBtn1Click(Sender: TObject);
- procedure BitBtn4Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- uses Prevform;
-
- {$R *.DFM}
-
- procedure TForm1.BitBtn2Click(Sender: TObject);
- begin
- if OpenDialog1.Execute then
- Label3.Caption := OpenDialog1.FileName;
- end;
-
- procedure TForm1.BitBtn1Click(Sender: TObject);
- type
- PBuffer = ^TBuffer;
- TBuffer = array[0..65200] of char;
- var
- Form: file;
- Index: file of LongInt;
- i: LongInt;
- Buf: PBuffer;
- begin
- { assign and open selected file }
- AssignFile(Form, Label3.Caption);
- Reset(Form, 1);
- try
- { assign and create index file }
- AssignFile(Index, ChangeFileExt(Label3.Caption, '.NDX'));
- Rewrite(Index);
- { getmem for buffer Note: you would need to page
- files bigger than 64K if using Delphi 1}
- GetMem(Buf, FileSize(Form));
- try
- { read form into buffer }
- BlockRead(Form, Buf^, FileSize(Form));
- for i := 0 to FileSize(Form) do
- if Buf^[i] = '@' then { found marker }
- begin
- Write(Index, i); { write offset to index }
- ListBox1.Items.Add(IntToStr(i)); { display offset for user }
- end;
- finally
- { clean up }
- FreeMem(Buf, FileSize(Form));
- end;
- finally
- { clean up }
- CloseFile(Form);
- CloseFile(Index)
- end;
- end;
-
- procedure TForm1.BitBtn4Click(Sender: TObject);
- var
- i, j: integer;
- F: TFileStream;
- Index: file of integer;
- S: string;
- begin
- { open form file }
- F := TFileStream.Create(Label3.Caption, fmOpenWrite);
- try
- { assign and open index file }
- AssignFile(Index, ChangeFileExt(Label3.Caption, '.NDX'));
- Reset(Index);
- try
- { iterate through index offsets }
- for j := 0 to FileSize(Index)-1 do
- begin
- Read(Index, i);
- { seek to offset }
- F.Seek(i, 0);
- S := Format('%10s', ['Offset '+IntToStr(i)]);
- { write data to stream }
- F.Write(S[1], Length(S));
- end;
- finally
- CloseFile(Index);
- end;
- finally
- { clean up }
- F.Free;
- end;
- { show file in memo }
- CCForm.FileToShow := Label3.Caption;
- CCForm.Show;
- end;
-
- end.
-